package tr3dtris.utils;

import java.awt.Point;

/**
 * Static utility class used for Maths.
 * @author Luciano Mammino <loige@hotmail.com>
 * @author Andrea Mangano <kapitan0@hotmail.it>
 * @version 0.1
 * @since 0.1
 */
public class MathUtils {

    /**
     * Rotate a point to a given degree using a given rotation center point.
     * The result is approximated to the closest integer
     * @param point the point to be rotated
     * @param center the point used as center of rotation
     * @param theta the angle of rotation (should be in radiants)
     * @return the ressulting point whit coordinates approximated to the
     * closest integer
     */
    public static Point rotatePoint(Point point, Point center, double theta)
    {
        int x0 = center.x;
        int y0 = center.y;
        int x = point.x - x0;
        int y = point.y - y0;

        int xp = (int)Math.round( x * Math.cos(theta)
                      - y * Math.sin(theta) );

        int yp = (int)Math.round( x * Math.sin(theta)
                      + y * Math.cos(theta) );

        return new Point(xp +x0,yp+y0);
    }

    /**
     * Converts degree to radiants
     * @param degree
     * @return the angle value in radiants
     */
    public static double degree2rad(double degree)
    {
        return Math.PI * degree / 180;
    }


}